/**
 * ajax请求
 * @param url
 * @param param
 * @returns
 */
var root = "http://wq.guanaichou.cn/";

var vipCost = 40;

var customerSource = "android";

var version=2.4;

//var root="http://127.0.0.1:8080/";
function ajaxAction(url, param) {
	var obj;
	$.ajax({
		type: "POST",
		url: url,
		data: param,
		async: false,
		dataType: "json",
		success: function(msg) {
			if(msg) {
				obj = msg;
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("请求异常");
		}
	});
	return obj;
}


function ajaxActionText(url, param) {
	var obj;
	$.ajax({
		type: "GET",
		url: url,
		data: param,
		async: false,
		dataType: "text",
		success: function(msg) {
			if(msg) {
				obj = msg;
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("请求异常");
		}
	});
	return obj;
}

function ajaxGetAction(url, param) {
	var obj;
	$.ajax({
		type: "GET",
		url: url,
		data: param,
		async: false,
		dataType: "json",
		success: function(msg) {
			if(msg) {
				obj = msg;
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("请求异常");
		}
	});
	return obj;
}

/**
 * 时间格式化
 * @param value
 * @returns
 */
function formatDate(value) {
	if(value != null) {
		var date = new Date(value);
		if(date.getHours() == 0)
			return date.format("yyyy-MM-dd");
		else
			return date.format("yyyy-MM-dd hh:mm:ss");
	}
	return "";
}

Date.prototype.format = function(format) {
	var o = {
		"M+": this.getMonth() + 1, //month 
		"d+": this.getDate(), //day 
		"h+": this.getHours(), //hour 
		"m+": this.getMinutes(), //minute 
		"s+": this.getSeconds(), //second 
		"q+": Math.floor((this.getMonth() + 3) / 3), //quarter 
		"S": this.getMilliseconds() //millisecond 
	}

	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
		if(new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}

function isString(str) {
	return(typeof str == 'string') && str.constructor == String;
}

function isNull(obj) {
	return(obj == null || obj == undefined || obj == 'undefined' || obj == "" || obj.length == 0);
}
/*获取到Url里面的参数*/
(function($) {
	$.getUrlParam = function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r != null) return unescape(r[2]);
		return null;
	}
})(jQuery);

function isLogin() {
	if(isNull(localStorage.appUser)) {
		return false;
	}
	return true;
}


function showProvinceList() {
	var url = root + "myCenter/selectAreaInfoList";
	var html = '';
	mui.get(url, {
			grade: 1,
			pId: 0
		},
		function(result) {
			for(var i = 0; i < result.data.length; i++) {
				html += "<option value='" + result.data[i].id + "'>" + result.data[i].name + "</option>";
			}
			$("#provinceSelect").append(html);
		}, 'json');
}
/**
 * 城市数据
 * @param {Object} provinceId
 */
function showCitySelect(provinceId) {
	$("#citySelect").html("");
	var url = root + "myCenter/selectAreaInfoList";
	var html = '<option value="">请选择城市</option>';
	mui.get(url, {
			grade: 2,
			pId: provinceId
		},
		function(result) {
			if(result.data.length == 0) {
				mui.alert("该省份下的营业部还未开放，请选择其他省份");
				return;
			}
			for(var i = 0; i < result.data.length; i++) {
				html += "<option value='" + result.data[i].id + "'>" + result.data[i].name + "</option>";
			}
			$("#citySelect").append(html);
		}, 'json');
}
/**
 * 区域数据
 * @param {Object} cityId
 */
function showSubCitySelect(cityId) {
	$("#subCitySelect").html("");
	var url = root + "myCenter/selectAreaInfoList";
	var html = '<option value="">请选择区县</option>';
	mui.get(url, {
			grade: 3,
			pId: cityId
		},
		function(result) {
			for(var i = 0; i < result.data.length; i++) {
				html += "<option value='" + result.data[i].id + "'>" + result.data[i].name + "</option>";
			}
			$("#subCitySelect").append(html);
		}, 'json');
}

function checkVersion(){
	/*var result = ajaxGetAction(root+"index/selectVersion",{customerSource:customerSource});
	$.get(root+"index/selectVersion",{customerSource:customerSource},function(result){
		if(result.data.version!=version){
			alert("您的关爱筹应用版本需要更新，请点击确认下载最新的版本");
			window.location.href=result.data.downloadUrl;
	   }
	});*/
}

